package com.usian.controller;

import com.usian.entity.Result;
import com.usian.service.DeptService;
import com.usian.service.UserService;
import com.usian.user.Departments;
import com.usian.user.UserDeptDto;
import com.usian.user.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author:张永杰
 * @ClassName: UserController
 * @Date: 2024/12/11
 * @Description:
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 查询用户列表
     * @return
     */
    @GetMapping("/findAllUser")
    public Result<List<UserDeptDto>> findAllUser(){
        Result<List<UserDeptDto>> ulist =  userService.findAllUser();
        return ulist;
    }

    /**
     * 根据id查询
     * @param userId
     * @return
     */
    @GetMapping("getUserById/{userId}")
    public Users getUserById(@PathVariable("userId") Integer userId){
        Users users = userService.getById(userId);
        return users;
    }
    @Autowired
    private DeptService deptService;

    /**
     * 根据iD查询部门
     * @param deptId
     * @return
     */
    @GetMapping("getDeptById/{deptId}")
    public Departments getDeptById(@PathVariable("deptId")Integer deptId){
        return deptService.getById(deptId);
    }
}
